package cn.itcast.n4;

import lombok.extern.slf4j.Slf4j;

import static cn.itcast.n2.util.Sleeper.sleep;

/**
 * className: TestLiveLock
 * description:
 * date: 2023/2/22-11:43
 * <p>
 * project: concurrent
 * package: cn.itcast.n4
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
@Slf4j(topic = "c.TestLiveLock")
public class TestLiveLock {
    static volatile int count = 10;
    static final Object lock = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            while (count > 0) {
                sleep(0.2);
                count--;
                log.debug("count:{}", count);
            }
        }, "t1").start();
        new Thread(() -> {
            while (count < 20) {
                sleep(0.2);
                count++;
                log.debug("count:{}", count);
            }
        }, "t2").start();
    }
}
